const dayjs = require('dayjs')
const genId = require('../utils/genId')
const R = require('ramda')
const ValueObject = require('../valueObject/VelueObject')
const formatterTime = (t) => dayjs(t).format('YYYY-MM-DD HH:mm:ss')
class Entity extends ValueObject {
  id
  createdAt
  updatedAt
  deletedAt
  createdBy
  updatedBy
  // deletedBy
  constructor(descriptor, data) {
    super(descriptor)
    this.id = data.id || genId()
    if (data.createdAt) this.createdAt = formatterTime(data.createdAt)
    if (data.updatedAt) this.updatedAt = formatterTime(data.updatedAt)
  }
  init(data) {
    Object.assign(this, R.omit(['id', 'createdAt', 'updatedAt'], data))
  }
}

module.exports = Entity
